# -*- encoding: utf-8 -*-
"""
File Name: launch
Description:
Author : 'lirui'
date: 2/6/2024
Contact: marjey_lee@163.com
Change Activity:
2/6/2024:
"""
import uvicorn
from fastapi import FastAPI
from starlette.middleware.cors import CORSMiddleware

from projects.monitoring.zabbix_monitoring.services.monitor_zabbix_pipline import ZabbixMonitorPipeline

_APP = FastAPI()

_APP.add_middleware(
    CORSMiddleware,
    allow_origins=['*'],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

_SERVER = ZabbixMonitorPipeline(monitor_interval=1)
_SERVER.start()


@_APP.get("/health_check")
def health_check():
    return _SERVER.health_check()


@_APP.get('/error_msg')
def error_msg():
    return _SERVER.get_error_msg()


def _main():
    uvicorn.run(_APP, host="0.0.0.0", port=8080)  # start fast api server


if __name__ == "__main__":
    _main()
